<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/css/style.css" type="text/css" media="all" />
    <link rel="stylesheet" href="./layui/css/layui.css">
</head>
<body>
<section class="w3l-login">
<div class="overlay">
    <div class="wrapper">
        <div class="form-section">
            <h3>注册</h3>
            <h6>注册就能登录</h6>
            <form action="" id="loginForm" method="post" class="layui-form" lay-filter="example" enctype="multipart/form-data">
                <div class="form-input">
                    <input type="text" name="name"  placeholder="用户名" required="" autofocus>
                </div>
                <div class="form-input">
                    <input type="password" name="password" id="pas" placeholder="密码" required="">
                </div>
                <div class="form-input">
                    <input type="password" name="newp" id="npas" placeholder="再次输入密码" required>
                </div>
                <div class="form-input">
                    <input type="email" name="email"  id="email" placeholder="电话" required>
                </div>
                <div>头像</div>

                <div class="form-input">
                    <input type="file" name="src"  id="filename">
                </div>
                <button type="submit" class="btn btn-primary theme-button mt-4" id="btn" lay-submit="" lay-filter="registbtn">注册</button>
                <div class="new-signup">
                    <p name="msg" class="signuplink" style="color: red"></p>
                </div>
            </form>
            <p class="signup">已有账户? <a href="/login.html" class="signuplink">登录</a></p>
        </div>
    </div>
</div>
<div id='stars'></div>
<div id='stars2'></div>
<div id='stars3'></div>

<!-- copyright -->
<div class="copy-right">
    <p>&copy;版权所有Java2103王浩 <a href="http://w3layouts.com/" target="_blank">W3Layouts</a></p>
</div>
</section>
<script src="./layui/layui.js"></script>
<script type="text/javascript">
    layui.use(function () {

        var layer = layui.layer
            , form = layui.form
            , $ = layui.$;
        /*var a=/^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/

        if ($("#pas").val!=$("#npas").val){
            $("p.signuplink").text("两次密码不一致")
            return false;
        }
        if ($("#filename")==null||$("#filename")==""){
            $("p.signuplink").text("头像不能为空")
            return false;
        }
        if (a.test($("#email"))){
            $("p.signuplink").text("邮箱格式不正确")
            return false;
        }
        $("p.signuplink").text("")*/
        form.on('submit(registbtn)', function (data) {
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // });
            var formData = new FormData(document.getElementById("loginForm"));

            $.ajax({
                url: "/user/regist" ,
                type: "post",
                data: formData,
                processData:false,  //
                contentType:false,
                success: function (result) {
                    console.log(result);
                    if (result.statusCode == "1004") {
                        // 跳转到后台管理系统的主页面中
                        window.location.href = "/login.html";
                    }else {
                        layer.alert(result.message, {
                            title: '注册错误消息'
                        });
                    }
                }
            });

            return false; // 取消表单的默认提交行为
        });



    })
</script>
</body>
</html>